﻿using System;
using System.Collections.Generic;

namespace Battle.Engine.util
{
    public class RandomUtil
    {
        public JRandom innerRandom;
        public JRandom otherRandom;

        public void SetSeed(long seed)
        {
            innerRandom = new JRandom(seed);
            Debug.LogFightMsg("random seed:" + seed);
        }

        public void SetSeedOther(long seed)
        {
            otherRandom = new JRandom(seed);
        }

        public double value
        {
            get
            {
                double v = innerRandom.nextDouble();
                //Debug.LogFightMsg("Value:" + v);
                return v;
            }
        }

        public double otherValue
        {
            get
            {
                return otherRandom.nextDouble();
            }
        }

        public double OtherRange(double min, double max)
        {
            double v = otherRandom.nextDouble();
            return v * (max - min) + min;
        }

        public double Range(double min, double max)
        {
            double v = innerRandom.nextDouble();
            //Debug.LogFightMsg("RangeDouble:" + (v * (max - min) + min));
            return v * (max - min) + min;
        }

        public int OtherRange(int min, int max)
        {
            double v = otherRandom.nextDouble();
            if (v == 1f)
            {
                return max - 1;
            }
            return (int)(v * (double)(max - min)) + min;
        }

        public int Range(int min, int max)
        {
            double v = innerRandom.nextDouble();
            if (v == 1f)
            {
                //Debug.LogFightMsg("RangeInt:" + (int)(max - 1));
                return max - 1;
            }
            //Debug.LogFightMsg("RangeInt:" + (int)((v * (double)(max - min)) + min));
            return (int)(v * (double)(max - min)) + min;
        }
    }
}
